// 图表配置模块：仅导出生成函数，便于按需加载
import type { EChartsOption } from 'echarts'
export type Period = 'week' | 'month'

export function getVisitorTrendOption(period: Period, data: number[]): EChartsOption {
  return {
    tooltip: { trigger: 'axis' },
    xAxis: {
      type: 'category',
      data:
        period === 'month'
          ? Array.from({ length: 30 }, (_, i) => `${i + 1}日`)
          : ['周一', '周二', '周三', '周四', '周五', '周六', '周日'],
    },
    yAxis: { type: 'value' },
    series: [
      {
        name: '访客单数量',
        data,
        type: 'line',
        smooth: true,
        itemStyle: { color: '#1890ff' },
        areaStyle: {
          color: {
            type: 'linear',
            x: 0,
            y: 0,
            x2: 0,
            y2: 1,
            colorStops: [
              { offset: 0, color: 'rgba(24, 144, 255, 0.3)' },
              { offset: 1, color: 'rgba(24, 144, 255, 0.05)' },
            ],
          },
        },
      },
    ],
  } as EChartsOption
}

export interface PropertyStatusData {
  name: string
  value: number
  color: string
}

export function getPropertyStatusOption(data: PropertyStatusData[]): EChartsOption {
  return {
    tooltip: { trigger: 'item', formatter: '{a} <br/>{b}: {c} ({d}%)' },
    legend: { bottom: '0%' },
    series: [
      {
        name: '房源状态',
        type: 'pie',
        radius: ['40%', '70%'],
        avoidLabelOverlap: false,
        itemStyle: { borderRadius: 10, borderColor: '#fff', borderWidth: 2 },
        label: { show: true, formatter: '{b}: {c}' },
        data: data.map(item => ({
          value: item.value,
          name: item.name,
          itemStyle: { color: item.color }
        })),
      },
    ],
  } as EChartsOption
}

export interface AgentRankingData {
  name: string
  value: number
}

export function getAgentRankingOption(data: AgentRankingData[]): EChartsOption {
  return {
    tooltip: { trigger: 'axis', axisPointer: { type: 'shadow' } },
    grid: { left: '3%', right: '4%', bottom: '3%', containLabel: true },
    xAxis: { type: 'value' },
    yAxis: { type: 'category', data: data.map(item => item.name) },
    series: [
      {
        name: '成交单数',
        type: 'bar',
        data: data.map(item => item.value),
        itemStyle: {
          color: {
            type: 'linear',
            x: 0,
            y: 0,
            x2: 1,
            y2: 0,
            colorStops: [
              { offset: 0, color: '#1890ff' },
              { offset: 1, color: '#52c41a' },
            ],
          },
          borderRadius: [0, 4, 4, 0],
        },
      },
    ],
  } as EChartsOption
}
